var vm = new Vue({
    el: 'body',
    data: {
        marktext: '',
        edit: false
    },
    methods: {
        loadLast: function () {
            var lastmark = localStorage.getItem(location.pathname) || '';
            this.marktext = lastmark;
        },
        keyHandler: function (event) {
            console.log(event);
        }
    },
    filters: {
        marked: marked
    },
    watch:{
        marktext: function (marktext) {
            if(editing){
                localStorage.setItem(location.pathname, marktext);
            }
        }
    }
});
var editing = getParameterByName('edit') || false;
if(editing){
    vm.edit = true;
    vm.loadLast();
}else{
    var pageName = location.pathname.split('/').pop().split('.')[0] || 'index';
    $.get(pageName+'.md', function(data){
        vm.marktext =  data;
    });
}

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}